<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>条件查询</span>
      </div>
      <el-form :model="searchForm" class="demo-form-inline" size="mini" label-width="100px">
        <el-row :gutter="20">
          <el-col :span="6">
            <el-form-item label="订单编号">
              <el-input v-model="searchForm.orderSn" size="mini" placeholder="请填写订单编号" />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="类型">
              <el-select v-model="searchForm.orderType " size="mini" placeholder="订单类型">
                <el-option label="正常订单" value="0" />
                <el-option label="秒杀订单" value="1" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="支付方式">
              <el-select v-model="searchForm.payType " size="mini" placeholder="支付方式">
                <el-option label="未支付" value="0" />
                <el-option label="支付宝" value="1" />
                <el-option label="微信" value="2" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="订单状态">
              <el-select v-model="searchForm.status " size="mini" placeholder="订单状态">
                <el-option label="待付款" value="0" />
                <el-option label="待发货" value="1" />
                <el-option label="已发货" value="2" />
                <el-option label="已完成" value="3" />
                <el-option label="已关闭" value="4" />
                <el-option label="无效订单" value="5" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="box">
        <div class="btns">
          <el-button class="search" type="primary" size="mini" @click="search">搜索</el-button>
          <el-button class="reset" size="mini" @click="reset">重置</el-button>
        </div>
      </div>
    </el-card>
    <!-- 列表 -->
    <el-card>
      <el-table
        v-loading="loading"
        :data="list"
        border
        style="width: 100%"
      >
        <el-table-column
          type="index"
          label="序号"
          width="50"
          align="center"
        />
        <el-table-column
          prop="orderSn"
          label="订单编号"
          width="300"
          align="center"
        />
        <el-table-column label="支付方式" width="200" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.payType === 0" effect="dark" size="medium " type="info">未支付</el-tag>
            <el-tag v-else-if="scope.row.payType === 1" effect="dark" size="medium ">
              <svg-icon icon-class="alipay" style="width:30px;height:30px" />
            </el-tag>
            <el-tag v-else effect="dark" size="medium" type="success">
              <svg-icon icon-class="weixin" style="width:30px;height:30px" />
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" width="200" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status === 0" effect="dark" type="danger">待付款</el-tag>
            <el-tag v-else-if="scope.row.status === 1" effect="dark" type="warning">待发货</el-tag>
            <el-tag v-else-if="scope.row.status === 2" effect="light">已发货</el-tag>
            <el-tag v-else-if="scope.row.status === 3" effect="dark" type="primary">已完成</el-tag>
            <el-tag v-else-if="scope.row.status === 4" effect="dark" type="info">已关闭</el-tag>
            <el-tag v-else-if="scope.row.status === 5" type="info">无效订单</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="添加时间"
          width="300"
          align="center"
        />
        <el-table-column
          prop="memberUsername"
          label="用户账号"
          width="300"
          align="center"
        />
        <el-table-column label="订单类型" width="200" align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.orderType == 1" type="warning">秒杀订单</el-tag>
            <el-tag v-else type="success">正常订单</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="note"
          label="备注"
          width="200"
          align="center"
        />
        <el-table-column
          fixed="right"
          label="操作"
          width="200"
          align="center"
        >
          <template slot-scope="scope">

            <el-button type="primary" style="width:150px" size="small" @click="check(scope.row)"><i class="el-icon-view" style="margin-right:6px" />查看订单</el-button>

          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :current-page="page.currentpage"
        :page-sizes="page.pagesizes"
        :page-size="page.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
  </div>
</template>
<script>
import { findOrdersByPage } from '@/api/order/index.js'
export default {
  data() {
    return {
      loading: false,
      list: [],
      searchForm: {
        orderSn: '',
        orderType: '',
        payType: '',
        status: ''
      },
      page: {
        currentpage: 1,
        pagesizes: [10, 20, 30],
        pagesize: 10,
        total: 0
      }
    }
  },
  computed: {
  },
  created() {
    this.getOrderList()
  },
  methods: {
    getOrderList() {
      this.loading = true
      findOrdersByPage(this.page.currentpage, this.page.pagesize, { ...this.searchForm }).then(res => {
        // console.log(res)
        this.list = res.data.rows
        this.page.total = res.data.total
      })
      this.loading = false
    },
    handleSizeChange(val) {
      this.page.pagesize = val
      this.getOrderList()
    },
    handleCurrentChange(val) {
      this.page.currentpage = val
      this.getOrderList()
    },
    search() {
      this.page = this.$options.data().page
      this.getOrderList()
    },
    reset() {
      this.searchForm = this.$options.data().searchForm
    },
    check(row) {
      //  this.$router.push({ name: 'EditArticle', params: { id: row.id }})
      this.$router.push({ name: 'Detail', params: { id: row.id }})
    }
  }
}
</script>
<style lang="scss" scoped>
  .el-card{
    margin: 30px;
    .box{
      display: flex;
      flex-direction: row-reverse;
      margin-top: 20px;
      .reset{
        margin: 0 20px;
      }
    }
  }
</style>
